package com.wolfking.jeesite.service;

import com.wolfking.jeesite.entity.Dict;
import com.wolfking.jeesite.mapper.DictMapper;
import com.wolfking.jeesite.mybatis.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 字典的服务
 * <p>
 *
 * @author wolfking@赵伟伟
 * @mail zww199009@163.com
 * @创作日期 2017年4月25日下午3:23:48
 * @版权 归wolfking所有
 */
@Service
public class DictService extends BaseService<Dict> {


    @Autowired
    private DictMapper dictMapper;

    @Transactional(readOnly = true)
    public List<String> getAllDictType() {
        return dictMapper.getAllType();
    }


    @Transactional(readOnly = true)
    public List<Dict> getByType(String type) {
        Dict dict = new Dict();
        dict.setType(type);
        return selectExample(dict);
    }

    @Transactional
    public String getSystemParameter(String parameter, String defaultValue) {
        List<Dict> dicts = getByType("sys_parameter");
        for (Dict dict : dicts) {
            if (dict.getLabel().equals(parameter)) {
                return dict.getValue();
            }
        }
        return defaultValue;
    }

    @Transactional
    public String getSsoConfig(String parameter, String defaultValue) {
        List<Dict> dicts = getByType("sso_config");
        for (Dict dict : dicts) {
            if (dict.getLabel().equals(parameter)) {
                return dict.getValue();
            }
        }
        return defaultValue;
    }
}
